package com.fl.nettydemo.c3;

import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * netty的future 一般在线程池中使用
 */
@Slf4j
public class TestNettyFutureTask {
    @SneakyThrows
    public static void main(String[] args) {
        NioEventLoopGroup loopGroup = new NioEventLoopGroup();
        EventLoop eventLoop = loopGroup.next();
        Future<Integer> future = eventLoop.submit((Callable<Integer>) () -> {
            log.info("执行future任务");
            return 50;
        });

//        log.info("等待结果");
//        log.info("结果为-》:{}",future.get());

        future.addListener(new GenericFutureListener<Future<? super Integer>>() {
            @Override
            public void operationComplete(Future<? super Integer> future) throws Exception {
                log.info("结果：{}",future.getNow());
            }
        });
    }
}
